package com.itheima.condition;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.env.StandardEnvironment;
import org.springframework.core.type.AnnotatedTypeMetadata;

import java.security.spec.ECField;
import java.util.Map;

/**
 * @author wuli
 * @create 2022-01-08 22:37
 */
public class WindowsCondition implements Condition {
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        Environment environment = context.getEnvironment();
        if (environment instanceof StandardEnvironment) {
            StandardEnvironment standardEnvironment = (StandardEnvironment) environment;
            Map<String, Object> systemProperties = standardEnvironment.getSystemProperties();
            for (Map.Entry entry : systemProperties.entrySet()) {
                System.out.println(entry.getKey() + ": " + entry.getValue());
            }
        }
        String osName = environment.getProperty("os.name");
        osName = "Windows";
        if (osName.contains("Windows")) {
            return true;
        }
        return false;
    }
}
